<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>干扰告警管理</title>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	
	function postExcelFile(params, url) { //params是post请求需要的参数，url是请求url地址
	    var form = document.createElement("form");
	    form.style.display = 'none';
	    form.action = url;
	    form.method = "post";
	    document.body.appendChild(form);
	
	    for(var key in params){
	      var input = document.createElement("input");
	      input.type = "hidden";
	      input.name = key;
	      input.value = params[key];
	      form.appendChild(input);
	    }
	
	    form.submit();
	    form.remove();
	}
	
    function exportAlarmHistoryInCurrentPage(){
    	var rows  = $('#dg').datagrid("getRows");
		if (rows.length < 1) {
			$.messager.alert("系统提示", "请查询需要导出的数据");
			return;
		}
    	var params = {data:JSON.stringify(rows)};
    	postExcelFile(params, "${pageContext.request.contextPath}/interferencequery/exportcurrentpageAlarm.do");
	}
    
    function getCommonData() {
    	var startTime = $("#i1").datebox("getValue");
		var endTime = $("#i2").datebox("getValue");
		var startTimeLong = new Date(startTime.replace(new RegExp("-","gm"),"/")).getTime();
		var endTimeLong = new Date(endTime.replace(new RegExp("-","gm"),"/")).getTime();
		var frontId = $("#frontId").combobox("getText");
		//var interference_type = $("#interference_type").combobox("getText");
		return {"startTime": startTimeLong, "endTime": endTimeLong, "frontId": frontId};
    }
    
    function exportAlarmHistoryInAllPages(){
		var data = getCommonData();
		window.open('${pageContext.request.contextPath}/interferencequery/exportAlarm.do?frontId='+data.frontId+'&startTime='+data.startTime+'&endTime='+data.endTime);
    }
    
    function sendData(data) {
    	$("#dg").datagrid('load',{
			"frontId": data.frontId,
			"interference_type": data.interferenceType,
		 	"startTime": data.startTime,
		 	"endTime": data.endTime
		 });
    }
    
	function searchAlarmhistory(){
		var data = getCommonData();
		if(data.startTime - data.endTime >= 0){
			$.messager.alert("系统提示","查询开始时间"+startTime+"不能大于结束时间"+endTime+"！");
			return;
		}
		sendData(data);
	}
    
	function markHandled() {
		var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要标记的数据！");
			 return;
		 }
		 var frontIds=[];
		 var directions=[];
		 var timeStamps=[];
		 for(var i=0;i<selectedRows.length;i++){
			 frontIds.push(selectedRows[i].frontId);
			 directions.push(selectedRows[i].direction);
			 timeStamps.push(selectedRows[i].timeStamp);
		 }
		 var FIDs=frontIds.join(",");
		 var DIRs=directions.join(",");
		 var TIMS=timeStamps.join(",");
		 var isDisposed=1;
		 $.messager.confirm("系统提示","您确定要标记这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
				if(r){
					$.post("${pageContext.request.contextPath}/interferencequery/changealarmstatus.do",{FIDs:FIDs,DIRs:DIRs,TIMS:TIMS},function(result){
						if(result.success){
							 $.messager.alert("系统提示","已标记成功！");
							 searchAlarmhistory();
						}else{
							$.messager.alert("系统提示","标记失败，请联系系统管理员！");
						}
					},"json");
				} 
			 });
	}
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="干扰查询管理" class="easyui-datagrid" fitColumns="fasle" pagination="true" rownumbers="true" pageSize="100" pageList="[100,200,300,400,500]"
   url="${pageContext.request.contextPath}/interferencequery/alarmhistory.do" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="alarmLevel" width="60" align="center">告警级别</th>
   		<th field="frontId" width="100" align="center">前置机号</th>
   		<th field="BSName" width="120" align="center">基站</th>
   		<th field="timeBegin" width="180" align="center">开始时间</th>
   		<th field="timeStamp" width="180" align="center">结束时间</th>
   		<th field="direction" width="80" align="center">上下行</th>
   		<th field="infIntensity" width="140" align="center">干扰强度</th>
   		<th field="infChannel" width="80" align="center">干扰频道</th>
   		<th field="infType" width="180" align="center">干扰类型</th>
   		<th field="infSourceType" width="140" align="center">干扰源类型</th>
   		<th field="isDisposed" width="80" align="center">是否处理</th>
   	</tr>
   </thead>
 </table>
 <div id="tb">
    <div>
    	<a href="javascript:exportAlarmHistoryInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出当前干扰告警记录</a>
 		<a href="javascript:exportAlarmHistoryInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出所有干扰告警记录</a>
    </div>
 	<div>
 		&nbsp;&nbsp;小区：
 		<input class="easyui-combobox" id="frontId" name="frontId" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/frontId.do'" value="-1"/>   
 		<!-- 
 		&nbsp;&nbsp;&nbsp;干扰类型：
 		<input class="easyui-combobox" id="interference_type" name="interference_type" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/interferencelist.do'" value="-1"/> 
 		-->
 		&nbsp;&nbsp;&nbsp;时间：<input type="text" id="i1" size="20" class="easyui-datetimebox" style="width:150px" />&nbsp;至&nbsp;
		<input type="text" id="i2" size="20" class="easyui-datetimebox"  style="width:150px" />
		
 		<a href="javascript:searchAlarmhistory()" class="easyui-linkbutton" iconCls="icon-search" plain="true"><b style="font-size:15px">搜索</b></a>
 		<c:if test="${currentMemberShip.group.name=='管理员' }">
 		<a href="javascript:markHandled()" class="easyui-linkbutton" iconCls="icon-check" plain="true">标记为已处理</a>
 		<!-- <a href="javascript:markUnHandled()" class="easyui-linkbutton" iconCls="icon-check" plain="true">标记为未处理</a> -->
 		</c:if>
 	</div>
 </div>
	
</body>
</html>